using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;

using ILRuntime.CLR.TypeSystem;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.Runtime.Stack;
using ILRuntime.Reflection;
using ILRuntime.CLR.Utils;
using System.Linq;

namespace ILRuntime.Runtime.Generated
{
    unsafe class huqiang_Data_UnsafeOperation_Binding
    {
        public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
        {
            BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
            MethodBase method;
            Type[] args;
            Type type = typeof(huqiang.Data.UnsafeOperation);
            args = new Type[]{typeof(System.Object)};
            method = type.GetMethod("GetStructAddr", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, GetStructAddr_0);
            args = new Type[]{typeof(System.Object)};
            method = type.GetMethod("GetObjectAddr", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, GetObjectAddr_1);
            args = new Type[]{typeof(System.IntPtr), typeof(System.Boolean)};
            method = type.GetMethod("GetFeildOffset", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, GetFeildOffset_2);
            args = new Type[]{typeof(System.IntPtr), typeof(System.Object)};
            method = type.GetMethod("SetObject", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, SetObject_3);
            args = new Type[]{typeof(System.IntPtr)};
            method = type.GetMethod("GetObject", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, GetObject_4);
            args = new Type[]{typeof(System.IntPtr), typeof(System.Int32)};
            method = type.GetMethod("GetListElement", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, GetListElement_5);





        }


        static StackObject* GetStructAddr_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object @obj = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)0);
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = huqiang.Data.UnsafeOperation.GetStructAddr(@obj);

            __ret->ObjectType = ObjectTypes.Integer;
            *(IntPtr*)&__ret->Value = result_of_this_method;
            return __ret + 1;
        }

        static StackObject* GetObjectAddr_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object @obj = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)0);
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = huqiang.Data.UnsafeOperation.GetObjectAddr(@obj);

            __ret->ObjectType = ObjectTypes.Integer;
            *(IntPtr*)&__ret->Value = result_of_this_method;
            return __ret + 1;
        }

        static StackObject* GetFeildOffset_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Boolean @isStruct = ptr_of_this_method->Value == 1;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.IntPtr @ptr = *(IntPtr*)&ptr_of_this_method->Value;


            var result_of_this_method = huqiang.Data.UnsafeOperation.GetFeildOffset(@ptr, @isStruct);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value = result_of_this_method;
            return __ret + 1;
        }

        static StackObject* SetObject_3(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object @obj = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.IntPtr @tar = *(IntPtr*)&ptr_of_this_method->Value;


            huqiang.Data.UnsafeOperation.SetObject(@tar, @obj);

            return __ret;
        }

        static StackObject* GetObject_4(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.IntPtr @tar = *(IntPtr*)&ptr_of_this_method->Value;


            var result_of_this_method = huqiang.Data.UnsafeOperation.GetObject(@tar);

            object obj_result_of_this_method = result_of_this_method;
            if(obj_result_of_this_method is CrossBindingAdaptorType)
            {    
                return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance, true);
            }
            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true);
        }

        static StackObject* GetListElement_5(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @index = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.IntPtr @ptr = *(IntPtr*)&ptr_of_this_method->Value;


            var result_of_this_method = huqiang.Data.UnsafeOperation.GetListElement(@ptr, @index);

            __ret->ObjectType = ObjectTypes.Integer;
            *(IntPtr*)&__ret->Value = result_of_this_method;
            return __ret + 1;
        }





    }
}
